<?php

namespace app\admin\model\user;

use think\Model;


class UserMoneyLog extends Model
{

    

    

    // 表名
    protected $name = 'user_money_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text'
    ];
    

    
    public function getTypeList()
    {
        return ['1' => __('Commission'), '2' => __('Integral')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function add_money_log($user_id,$money,$before,$after,$memo,$type=1){
        $this->user_id = $user_id;
        $this->money = $money;
        $this->before = $before;
        $this->after = $after;
        $this->memo = $memo;
        $this->type = $type;
        $this->save();
        return true;
    }
}
